#include <iostream>
using namespace std;
#include <map>

// map容器 大小和交换
void printMap(map<int, int>& m)
{
    for (map<int, int>::iterator it = m.begin();it != m.end();it++)
    {
        cout << "key = " << (*it).first
            << "  value = " << it->second << endl;
    }
    cout << endl;
}

// 大小
void test1()
{
    map<int, int> m1;
    m1.insert(pair<int, int>(1, 10));
    m1.insert(pair<int, int>(4, 40));
    m1.insert(pair<int, int>(2, 20));
    m1.insert(pair<int, int>(3, 30));

    if (m1.empty())
    {
        cout << "m1为空" << endl;
    }
    else
    {
        cout << "m1不为空" << endl;
        cout << "m1的大小为：" << m1.size() << endl;
    }
}

// 交换
void test2()
{
    map<int, int> m1;
    m1.insert(pair<int, int>(1, 10));
    m1.insert(pair<int, int>(4, 40));
    m1.insert(pair<int, int>(2, 20));
    m1.insert(pair<int, int>(3, 30));

    map<int, int> m2;
    m2.insert(pair<int, int>(5, 50));
    m2.insert(pair<int, int>(7, 70));
    m2.insert(pair<int, int>(6, 60));
    m2.insert(pair<int, int>(8, 80));

    cout << "交换前：" << endl;
    printMap(m1);
    printMap(m2);

    m1.swap(m2);
    cout << "交换后：" << endl;
    printMap(m1);
    printMap(m2);
}

int main()
{
    test1();
    cout << "================" << endl;
    test2();
    return 0;
}